package interview.base;

import java.util.ArrayList;

import java.util.List;
import java.util.Objects;

public class ListRemove {

    public static void main(String[] args) {
        List<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(1);
        list.add(2);
        System.out.println(list);
        list.remove(1);
        System.out.println(list);
        System.out.println("~~~~~~~~~~~~~~~~~~~~~");
        List<User> users = new ArrayList<>();
        User user1 = new User("111","111");
        User user2 = new User("222","222");
        User user3 = new User("333","333");
        User user4 = new User("333","333");
        users.add(user1);
        users.add(user2);
        users.add(user3);
        users.add(user4);
        System.out.println(users);
        users.remove(user3);
        System.out.println("第一次移除："+users);
        users.remove(user3);
        System.out.println("第二次移除："+users);
        users.remove(user3);
        System.out.println("第次移除："+users);
    }

}

class User{

    private String username;

    private String password;

    public User(String username, String password) {
        this.username = username;
        this.password = password;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        User user = (User) o;
        return Objects.equals(username, user.username) &&
                Objects.equals(password, user.password);
    }

    @Override
    public int hashCode() {
        return Objects.hash(username, password);
    }

    @Override
    public String toString() {
        return "User{" +
                "username='" + username + '\'' +
                ", password='" + password + '\'' +
                '}';
    }
}
